package com.liugui;

/**
 * @ClassName: InterruptDemo
 * @Author: liugui
 * @Date: 2021-05-19 15:31
 **/
public class InterruptDemo {
    public static void main(String[] args) {
        MyThread4 my4 = new MyThread4();
        Thread thread = new Thread(my4);
        thread.start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            System.out.println("休眠终止");
        }
        thread.interrupt();//中断线程 进入线程终止
        System.out.println("主线程结束");
    }
}

class MyThread4 implements Runnable{
    @Override
    public void run() {
        System.out.println("进入run方法");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            System.out.println("线程终止");
            return;
        }
        System.out.println("run执行完毕");
    }
}